//
//  DDCommunicateBossViewController.m
//  DingDongZP
//
//  Created by Jyh on 16/3/29.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

#import "DDCommunicateBossViewController.h"
#import "DDDiscoverJobCell.h"
#import "DDWorkDetailViewController.h"
#import "DDCommunicatedStore.h"

@interface DDCommunicateBossViewController ()

@end

@implementation DDCommunicateBossViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"沟通过的Boss";
    
    [self configureTableView];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    ///	界面显示后读取缓存，免得会卡界面
    NSArray *storedJobs = [[DDCommunicatedStore sharedStore] communicatedBosses];
    NSMutableArray *filteredJobs = [NSMutableArray array];
    for (DDJobsDetail *detail in storedJobs) {
        if ([detail isKindOfClass:[DDJobsDetail class]]) {
            [filteredJobs addObject:detail];
        }
    }
    self.dataSource = filteredJobs;
    [self.tableView reloadData];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.rdv_tabBarController setTabBarHidden:true animated:true];
}


- (void)configureTableView
{
    self.tableView.rowHeight = 182;
    self.tableView.tableFooterView = [[UIView alloc] init];
    
    UINib *cellNib = [UINib nibWithNibName:@"DDDiscoverJobCell" bundle:nil];
    [self.tableView registerNib:cellNib forCellReuseIdentifier:DDDiscoverJobCellIdentifier];
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    //    [self addRefreshHeader];
    //    [self addRefreshFooter];
}

#pragma mark -
#pragma mark UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DDDiscoverJobCell *cell = (DDDiscoverJobCell *)[tableView dequeueReusableCellWithIdentifier:DDDiscoverJobCellIdentifier];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if ([self.dataSource count] > indexPath.row) {
        [cell updateViewWithData:(DDJobsDetail *)self.dataSource[indexPath.row]];
    }
    return cell;
}

#pragma mark -
#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    DDWorkDetailViewController *workVC = [[DDWorkDetailViewController alloc] init];
    workVC.jobDetail = (DDJobsDetail *)self.dataSource[indexPath.row];
    workVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:workVC animated:YES];
}

@end
